Skip to content

Cleanup clipboard tests #21163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 26, 2018

Conversation

david-liu-brattle-1
Copy link
Contributor

@david-liu-brattle-1 david-liu-brattle-1 commented May 22, 2018

As requested in #21111, I've refactored the original clipboard tests as well as adding my own. The set of tests have been improved to include testing of:

As a result, these tests will fail on the current master branch, but should succeed on the commit in #21111

@WillAyd

@pep8speaks
Copy link

pep8speaks commented May 22, 2018

Hello @david-liu-brattle-1! Thanks for updating the PR.

Line 140:74: W291 trailing whitespace

Comment last updated on June 23, 2018 at 19:07 Hours UTC

@jschendel jschendel added Testing pandas testing functions or related to the test suite Clean labels May 22, 2018
Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so what you can do is xfail the cases which don't work now but will work in the new PR.

tm.assert_frame_equal(data, result, check_dtype=False)

def test_round_trip_frame(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be parameterized or a fixture

@@ -60,6 +60,9 @@ def setup_class(cls):
# unicode round trip test for GH 13747, GH 12529
cls.data['utf8'] = pd.DataFrame({'a': ['µasd', 'Ωœ∑´'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can remove this entirely and use fixtures

def test_round_trip_frame(self):
for dt in self.data_types:
self.check_round_trip_frame(dt)

def test_round_trip_frame_sep(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these can all be parameterized

with tm.assert_produces_warning():
self.data['string'].to_clipboard(excel=True, sep=r'\t')

def build_kwargs(self, sep, excel):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can make this a module level function

(None, False),
('default', False)
])
def test_clipboard_copy_strings(self, sep, excel):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can parameterize over data_types as well

@david-liu-brattle-1
Copy link
Contributor Author

@jreback
I made some changes to the testing setup. Is this what you had in mind?

@codecov
Copy link

codecov bot commented Jun 6, 2018

Codecov Report

Merging #21163 into master will increase coverage by 0.06%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #21163      +/-   ##
==========================================
+ Coverage   91.84%    91.9%   +0.06%     
==========================================
  Files         153      154       +1     
  Lines       49505    49562      +57     
==========================================
+ Hits        45466    45549      +83     
+ Misses       4039     4013      -26
Flag Coverage Δ
#multiple 90.3% <ø> (+0.06%) ⬆️
#single 42.02% <ø> (+0.14%) ⬆️
Impacted Files Coverage Δ
pandas/io/formats/csvs.py 97.67% <0%> (-0.47%) ⬇️
pandas/core/panel.py 97.44% <0%> (-0.43%) ⬇️
pandas/core/indexes/datetimes.py 95.66% <0%> (-0.12%) ⬇️
pandas/core/indexes/multi.py 94.89% <0%> (-0.11%) ⬇️
pandas/io/json/normalize.py 96.87% <0%> (-0.07%) ⬇️
pandas/core/indexes/base.py 96.63% <0%> (-0.06%) ⬇️
pandas/core/arrays/categorical.py 95.63% <0%> (-0.04%) ⬇️
pandas/core/frame.py 97.19% <0%> (-0.04%) ⬇️
pandas/core/indexes/category.py 97.01% <0%> (-0.03%) ⬇️
pandas/core/dtypes/common.py 94.63% <0%> (-0.02%) ⬇️
... and 31 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 172ab7a...2613a06. Read the comment docs.

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do all of these tests actually need xfailing?

with tm.assert_produces_warning():
gen_df('string').to_clipboard(excel=True, sep=r'\t')

@pytest.mark.xfail
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for tests that xfail, pls provide a reason

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I add comments in the code with the reason?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes if they are xfailing, reference the issue number and a brief description. (when the bug is fixed will remove the xfails, but that's in a subsequent PR).

def test_round_trip_frame(self, df):
self.check_round_trip_frame(df)

def test_round_trip_frame_sep(self, df):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can parameterize on the sep

@pytest.fixture(params=['delims', 'utf8', 'string', 'long', 'nonascii',
'colwidth', 'mixed', 'float', 'int'])
def df(request):
return gen_df(request.param)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just move gen_df inside the fixture itself, I think makes it more clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gen_df is called directly from some of the tests. The fixture is called using a a pytest object and gen_df needs to be called with a string argument. Is there a better workaround than separating the two functions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can change it to something like this, but I think separating the two out is still preferable.

@pytest.fixture(params=['delims', 'utf8', 'string', 'long', 'nonascii',
                        'colwidth', 'mixed', 'float', 'int'])
def df(request):
    if type(request) is str:
        data_type = request
    else:
        data_type = request.param

    if data_type == 'delims':
        return pd.DataFrame({'a': ['"a,\t"b|c', 'd\tef´'],
                             'b': ['hi\'j', 'k\'\'lm']})
    elif data_type == 'utf8':
        return pd.DataFrame({'a': ['µasd', 'Ωœ∑´'],
                             'b': ['øπ∆˚¬', 'œ∑´®']})

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh didn't see that, though then this begs the question of why you are not simply passing the constructed df in?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point, I'll update

# delimited and excel="True"
# Fails because to_clipboard defaults to space delim.
# Issue in #21104, Fixed in #21111
@pytest.mark.xfail
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

every xfail needs a reason

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you take a look at the latest version? Is that what you meant for reason?

@jreback jreback added this to the 0.23.2 milestone Jun 26, 2018
Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor comment. all of the currently xfailed ones are fixed by #21111 ?

@pytest.mark.xfail(reason="Not yet implemented. Fixed in #21111")
def test_excel_sep_warning(self):
with tm.assert_produces_warning():
gen_df('string').to_clipboard(excel=True, sep=r'\t')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so instead of calling gen_df inside a test, just create a nother fixture, simplier that way I think
e.g.

@pytest.fixture
def df_string():
    return gen_df('string')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that makes a lot of sense and I'll keep that in mind for future cases. I went a different way and just ran that test function on the entire df fixture, which is a little cleaner.

@david-liu-brattle-1
Copy link
Contributor Author

@jreback
Yes, all xfails pass in #21111

@jreback jreback merged commit 9d38e0e into pandas-dev:master Jun 26, 2018
@jreback
Copy link
Contributor

jreback commented Jun 26, 2018

thanks @david-liu-brattle-1 !

jorisvandenbossche pushed a commit to jorisvandenbossche/pandas that referenced this pull request Jul 2, 2018
jorisvandenbossche pushed a commit that referenced this pull request Jul 5, 2018
(cherry picked from commit 9d38e0e)
Sup3rGeo pushed a commit to Sup3rGeo/pandas that referenced this pull request Oct 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Clean Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants